<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Domain Socket Support</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="mongo.connecting.mongos.html">« Sharding</a></li>
      <li style="float: right;"><a href="mongo.connecting.persistent.html">Persistent Connections (version 1.3.0+) »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="mongo.connecting.html">Connecting</a></li>
    <li>Domain Socket Support</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="mongo.connecting.uds" class="section">
  <h2 class="title">Domain Socket Support</h2>

  <p class="para">
   MongoDB has built-in support for connecting via Unix Domain Sockets and will
   open the socket on startup. By default, the socket is located in
   <var class="filename">/tmp/mongodb-&lt;port&gt;.sock</var>.
  </p>

  <p class="para">
   To connect to the socket file, specify the path in your MongoDB connection
   string:
  </p>

  <div class="example" id="mongo.connecting.uds-example">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$m&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoClient</span><span style="color: #007700">(</span><span style="color: #DD0000">"mongodb:///tmp/mongo-27017.sock"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>

  <p class="para">
   If you would like to authenticate against a database (as described above)
   with a socket file, you must specify a port of <code class="literal">0</code> so that
   the connection string parser can detect the end of the socket path.
   Alternatively, you can use the constructor options.
  </p>

   <div class="example" id="mongo.connecting.uds-auth-example">
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$m&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoClient</span><span style="color: #007700">(</span><span style="color: #DD0000">"mongodb://username:password@/tmp/mongo-27017.sock:0/foo"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>

  <div class="simplesect">
   <h3 class="title">Changelog</h3>
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>1.0.9</td>
       <td>
        Added support for Unix Domain Sockets.
       </td>
      </tr>

     </tbody>
    
   </table>

  </div>

 </div></div></div></body></html>